package com.atguigu.gmall.product.service.impl;

import com.alibaba.fastjson.JSON;
import com.atguigu.gmall.product.entity.SpuSaleAttr;
import com.atguigu.gmall.product.mapper.SpuSaleAttrMapper;
import com.atguigu.gmall.product.service.SpuSaleAttrService;
import com.atguigu.gmall.product.vo.ValuesSkuJsonVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 *
 */
@Service
public class SpuSaleAttrServiceImpl extends ServiceImpl<SpuSaleAttrMapper, SpuSaleAttr> implements SpuSaleAttrService {

    @Autowired
    SpuSaleAttrMapper spuSaleAttrMapper;

    @Override
    public List<SpuSaleAttr> spuSaleAttrList(Long spuId) {
        return baseMapper.spuSaleAttrList(spuId);
    }

    @Override
    public List<SpuSaleAttr> getSpuSaleAttrListOrder(Long spuId, Long skuId) {
        return spuSaleAttrMapper.getSpuSaleAttrListOrder(spuId,skuId);
    }

    @Override
    public String getValuesSkuJson(Long spuId) {
        List<ValuesSkuJsonVo> valuesSkuJsonVoList = spuSaleAttrMapper.getValuesSkuJson(spuId);
        Map<String, Long> map = valuesSkuJsonVoList.stream().collect(Collectors.toMap(t -> t.getValueJson(), t -> t.getSkuId()));
        String string = JSON.toJSONString(map);
        return string;
    }
}




